﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using DAO;
using BUS;

namespace QuanLyKhachSan
{
    public partial class BaoCaoDoanhThu : Form
    {
        public BaoCaoDoanhThu()
        {
            InitializeComponent();
        }
        
        public bool KiemTraDaTonTai(string tenloaiphong,List<MyLoaiPhong> ds)
        {
            
            
            for(int i=0;i<ds.Count;i++)
                if(ds[i].TenLoaiPhong == tenloaiphong)
                    return true;
            return false;
        }
        private void button3_Click(object sender, EventArgs e)
        {
            list_BaoCao.Items.Clear();
            DateTime thangBC = ThangBaoCao.Value;
            int thang = thangBC.Month;
            int nam = thangBC.Year;
            //List<HoaDonDTO> dsHoaDon = BUS.HoaDonBUS.layDSHoaDonTheoThangvaNam(thang.ToString(), nam.ToString());
           // List<ChiTietPhieuThueDTO> dsCTPhieuThue = BUS.ChiTietPhieuThueBUS.layDSCTPTtheoDSMaHD(dsHoaDon);
            double TongTien = 0;
            List<BaoCaoDTO> dsBaoCao = BUS.BaoCaoBUS.layDSBaoCaoTheoThangvaNam(thang.ToString(), nam.ToString());
            if (dsBaoCao.Count == 0)
            {
                MessageBox.Show("Tháng này không có hóa đơn !!!", "Thông báo !!!");
            }
            else
            {
                for (int j = 0; j < dsBaoCao.Count; j++)
                {
                    TongTien += dsBaoCao[j].ThanhTien;
                }
                List<BaoCaoDTO> dsLoaiPhong = BUS.BaoCaoBUS.thongKeTheoLoaiPhong(dsBaoCao);
                for (int i = 0; i < dsLoaiPhong.Count; i++)
                {
                    ListViewItem item = new ListViewItem((i + 1).ToString(), i);
                    item.SubItems.Add(dsLoaiPhong[i].TenLoaiPhong);
                    item.SubItems.Add(dsLoaiPhong[i].ThanhTien.ToString());
                    double tyle = dsLoaiPhong[i].ThanhTien / TongTien;
                    tyle = Math.Round(tyle, 3);
                    item.SubItems.Add(tyle.ToString());
                    list_BaoCao.Items.Add(item);
                }
                txt_TongTien.Text = TongTien.ToString();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Chắc chắn muốn thoát ???", "Warning !!!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                this.Close();
        }

        private void BaoCaoDoanhThu_Load(object sender, EventArgs e)
        {
            ThangBaoCao.Value = DateTime.Now;
        }
    }
}
